﻿
using DataModels.Enums.WorkOrder;
using Utils;
using static DataModels.Enums.GeneralEnum;

namespace DataModels.Dto.WorkOrder
{

    using System;
    using System.ComponentModel.DataAnnotations;

    /// <summary>
    /// 报单/业务请求模型
    /// </summary>
    public class SigeCreateWorkOrderInfoRequest
    {
        /// <summary>
        /// 报单地址（房屋地址）
        /// 示例值："XX市XX区XX街道XX号"
        /// </summary>
        [MaxLength(200, ErrorMessage = "地址长度不能超过 200 字符")]
        public string address { get; set; }

        /// <summary>
        /// 预约开始时间（时间格式: yyyy-MM-dd HH:mm:ss）
        /// 示例值："2024-01-01 09:00:00"
        /// </summary>
        [RegularExpression(@"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$",
            ErrorMessage = "预约开始时间格式必须为 yyyy-MM-dd HH:mm:ss")]
        public string bespeakBeginTime { get; set; }

        /// <summary>
        /// 预约结束时间（时间格式: yyyy-MM-dd HH:mm:ss）
        /// 示例值："2024-01-01 10:00:00"
        /// </summary>
        [RegularExpression(@"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$",
            ErrorMessage = "预约结束时间格式必须为 yyyy-MM-dd HH:mm:ss")]
        public string bespeakEndTime { get; set; }

        /// <summary>
        /// 业务类型（必填）
        /// 示例值："维修"
        /// </summary>
        [Required(ErrorMessage = "业务类型为必填项")]
        [MaxLength(50, ErrorMessage = "业务类型长度不能超过 50 字符")]
        public string busiType { get; set; }

        /// <summary>
        /// 联系人
        /// 示例值："张三"
        /// </summary>
        [MaxLength(50, ErrorMessage = "联系人长度不能超过 50 字符")]
        public string contactName { get; set; }

        /// <summary>
        /// 联系电话（必填）
        /// 示例值："13800138000"
        /// </summary>
        [Required(ErrorMessage = "联系电话为必填项")]
        [Phone(ErrorMessage = "联系电话格式不正确")]
        [MaxLength(20, ErrorMessage = "联系电话长度不能超过 20 字符")]
        public string contactTel { get; set; }

        /// <summary>
        /// 内容（可描述业务详情）
        /// 示例值："客厅灯不亮"
        /// </summary>
        [Required(ErrorMessage = "内容为必填项")]
        [MaxLength(500, ErrorMessage = "内容长度不能超过 500 字符")]
        public string content { get; set; }

        /// <summary>
        /// 创建时间（时间格式: yyyy-MM-dd HH:mm:ss）
        /// 示例值："2024-01-01 08:00:00"
        /// </summary>
        [RegularExpression(@"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$",
            ErrorMessage = "创建时间格式必须为 yyyy-MM-dd HH:mm:ss")]
        public string createDate { get; set; }

        /// <summary>
        /// 传四格客户ID（选填）
        /// 示例值："CUST_001"
        /// </summary>
        [MaxLength(50, ErrorMessage = "传四格客户ID长度不能超过 50 字符")]
        public string custId { get; set; }

        /// <summary>
        /// 第三方项目ID（选填）
        /// 示例值："PROJ_001"
        /// </summary>
        [MaxLength(50, ErrorMessage = "第三方项目ID长度不能超过 50 字符")]
        public string eCommunityId { get; set; }

        /// <summary>
        /// 第三方房屋ID（选填）
        /// 示例值："HOUSE_001"
        /// </summary>
        [MaxLength(50, ErrorMessage = "第三方房屋ID长度不能超过 50 字符")]
        public string eHouseld { get; set; }

        /// <summary>
        /// 录入渠道（必填，7:第三方APP接入；11:微信-公众号）
        /// 示例值："11"
        /// </summary>
        [Range(7, 11, ErrorMessage = "录入渠道仅支持 7（第三方APP）或 11（微信公众号）")]
        public string enterChannel { get; set; } = "7";

        /// <summary>
        /// 传四格系统的房屋ID（选填）
        /// 示例值："HOUSE_SYSTEM_001"
        /// </summary>
        [MaxLength(50, ErrorMessage = "传四格系统的房屋ID长度不能超过 50 字符")]
        public string houseId { get; set; }

        /// <summary>
        /// 是否加急（0:不加急(默认)；1:加急）
        /// 示例值："0"
        /// </summary>
        [Range(0, 1, ErrorMessage = "是否加急仅支持 0（不加急）或 1（加急）")]
        public string isUrgent { get; set; } = "0"; // 默认不加急

        /// <summary>
        /// 项目ID（真实小区ID，必填）
        /// 示例值："123"
        /// </summary>
        [Required(ErrorMessage = "项目ID（真实小区ID，必填）")]
        public int main_segi_community_id { get; set; }

        /// <summary>
        /// 组织机构ID（与 eCommunityId 和 main_segl_community_id 必填其一，选填）
        /// 示例值："456"
        /// </summary>
        public int? main_segl_organ_id { get; set; }

        /// <summary>
        /// 公众号唯一标识（选填）
        /// 示例值："o6_bmjrPTlm6_2sgVt7hMZOPfL2M"
        /// </summary>
        [MaxLength(100, ErrorMessage = "公众号唯一标识长度不能超过 100 字符")]
        public string openId { get; set; }

        /// <summary>
        /// 第三方工单唯一标识（有则填写，选填）
        /// 示例值："ORDER_001"
        /// </summary>
        [MaxLength(50, ErrorMessage = "第三方工单唯一标识长度不能超过 50 字符")]
        public string orderKey { get; set; }

        /// <summary>
        /// 图片地址（选填，多张用逗号分隔）
        /// 示例值："http://xxx.com/img1.jpg,http://xxx.com/img2.jpg"
        /// </summary>
        [MaxLength(1000, ErrorMessage = "图片地址长度不能超过 1000 字符")]
        public string photos { get; set; }

        /// <summary>
        /// 工单所属的服务类型编码（服务大类，必填，参考《服务类型编码》）
        /// 示例值："SVC_001"
        /// </summary>
        [Required(ErrorMessage = "服务类型编码为必填项")]
        [MaxLength(50, ErrorMessage = "服务类型编码长度不能超过 50 字符")]
        public string serviceTypeCode { get; set; }

        /// <summary>
        /// 服务定义ID（通过《获取项目下开通的服务》可获取，与 serviceTypeCode 必填其一，选填）
        /// 示例值："SVC_DEF_001"
        /// </summary>
        [MaxLength(50, ErrorMessage = "服务定义ID长度不能超过 50 字符")]
        public string templateDifId { get; set; }
    }

    public class CreateWorkOrderInfo
    {
        [GeneralRequired]
        public Guid ProjectId { get; set; }

        [GeneralRequired]
        public int TypeId { get; set; }

        [GeneralRequired]
        public int HouseId { get; set; }

        [GeneralRequired]
        public string Phone { get; set; }

        [GeneralRequired]
        public string Description { get; set; }

        /// <summary>
        /// 期望上门时间
        /// </summary>
        public string? DoorTime { get; set; }

        public List<string> Urls { get; set; }
    }
    public class CancelledWorkOrder
    {
        public Guid WorkOrderId { get; set; }

        public string ReasonForChange { get; set; } = "";

        /// <summary>
        /// 物料UUID
        /// </summary>
        public string MaterialUUID { get; set; }

        /// <summary>
        /// 处理费用
        /// </summary>
        public decimal expenseAmount { get; set; } = 0;

        /// <summary>
        /// 工单状态 （1.已分配 2处理中 3等待用户反馈 4已解决）
        /// </summary>
        public WorkOrderStatus Status { get; set; }

        /// <summary>
        /// 处理人ID
        /// </summary>
        public Guid? ProcessorId { get; set; } = Guid.Empty;

        /// <summary>
        /// 已处理图片
        /// </summary>
        public List<string> Urls { get; set; } = new List<string>();
    }
    public class CancelledWorkOrderRapid
    {
        public Guid WorkOrderId { get; set; }

        public string ReasonForChange { get; set; } = "";

        /// <summary>
        /// 物料UUID
        /// </summary>
        public string? MaterialUUID { get; set; }

        /// <summary>
        /// 物料
        /// </summary>
        public string? material { get; set; }

        /// <summary>
        /// 处理费用
        /// </summary>
        public decimal expenseAmount { get; set; } = 0;

        /// <summary>
        /// 工单状态 （0.待处理 1.已分配 4已处理(待审核) 4.已处理(待审核) 5.已关闭）
        /// </summary>
        public WorkOrderRapidStatus Status { get; set; }

        /// <summary>
        /// 处理人ID
        /// </summary>
        public Guid? ProcessorId { get; set; } = Guid.Empty;

        /// <summary>
        /// 已处理图片
        /// </summary>
        public List<string> Urls { get; set; } = new List<string>();
    }

    public class UrgentWorkOrder
    {
        public Guid WorkOrderId { get; set; }
    }

    /// <summary>
    /// 取消
    /// </summary>
    public class discontinueWorkOrder
    {
        public Guid WorkOrderId { get; set; }
        public string ReasonForChange { get; set; }
    }

    /// <summary>
    /// 评价
    /// </summary>
    public class ResolvedWorkOrder
    {
        public Guid WorkOrderId { get; set; }
        public int SatisfactionScore { get; set; }
        public string? SatisfactionComment { get; set; }
    }

    public class GetWorkOrderInfo : PageRequest
    {
        public Guid WorkOrderId { get; set; } = Guid.Empty;
        public Guid? ProjectId { get; set; }

        public DateTime? StartTime { get; set; }

        public DateTime? EndTime { get; set; }

        /// <summary>
        /// 0待派单  2处理中 4已解决 5已评价 6已取消
        /// </summary>
        public List<WorkOrderStatus>? Status { get; set; } = [];

        /// <summary>
        /// 手机号用于更新四格工单
        /// </summary>
        public string Phone { get; set; } = "13222222222";
    }

    public class GetWorkOrderRapidInfo : PageRequest
    {
        public Guid WorkOrderId { get; set; } = Guid.Empty;
        public Guid? ProjectId { get; set; }

        public DateTime? StartTime { get; set; }

        public DateTime? EndTime { get; set; }

        public List<WorkOrderRapidStatus>? Status { get; set; } = [];

    }

    public class GetWorkOrderDto
    {
        public Guid WorkOrderId { get; set; }

        /// <summary>
        /// 工单编号
        /// </summary>
        public string OrderNo { get; set; }

        public string Type { get; set; }
        public string ProcessorName { get; set; }
        public string ProcessorPhone { get; set; }

        public string ProjectName { get; set; }

        /// <summary>
        /// 处理费用
        /// </summary>
        public decimal expenseAmount { get; set; }

        /// <summary>
        /// 工单描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 物料
        /// </summary>
        public string material { get; set; }

        public string ReasonForChange { get; set; }
        /// <summary>
        /// 电话号码
        /// </summary>
        public string Phone { get; set; }

        public List<string> Urls { get; set; }

        /// <summary>
        /// 已完成 图片地址列表
        /// </summary>
        public List<string> yiwagchenUrls { get; set; }
        public List<WorkOrderHistoryProgress> Progress { get; set; }

        public WorkOrderStatus Status { get; set; }

        public Status Urgent { get; set; }

        public DateTime CreateTime { get; set; }
    }
    public class GetWorkOrderRapidDto
    {
        public Guid WorkOrderId { get; set; }

        /// <summary>
        /// 工单编号
        /// </summary>
        public string OrderNo { get; set; }

        public string Type { get; set; }
        public string CreateName { get; set; }
        public string ProcessorName { get; set; }
        public string ProcessorPhone { get; set; }

        public string ProjectName { get; set; }

        public string FullAddress { get; set; }
        /// <summary>
        /// 处理费用
        /// </summary>
        public decimal expenseAmount { get; set; }

        /// <summary>
        /// 工单描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 物料
        /// </summary>
        public string material { get; set; }

        public string ReasonForChange { get; set; }
        /// <summary>
        /// 电话号码
        /// </summary>
        public string Phone { get; set; }

        public List<string> Urls { get; set; }

        /// <summary>
        /// 已完成 图片地址列表
        /// </summary>
        public List<string> yiwagchenUrls { get; set; }
        public List<WorkOrderHistoryProgress> Progress { get; set; }

        public WorkOrderRapidStatus Status { get; set; }

        public Status Urgent { get; set; }

        public DateTime CreateTime { get; set; }
    }
    public class GetWorkOrderResponse : GetWorkOrderDto
    {

        public new bool Urgent { get; set; }
    }
    public class GetWorkOrderrAPIDResponse : GetWorkOrderRapidDto
    {

        public new bool Urgent { get; set; }
    }

    public class GetWorkOrderHistoryDto
    {
        public string OrderNo { get; set; }
        public string PropertiesUUID { get; set; }
        public string Type { get; set; }
        public string FullAddress { get; set; }

        public string Phone { get; set; }

        public WorkOrderStatus Status { get; set; }

        public DateTime CreateTime { get; set; }

        public string Description { get; set; }

        /// <summary>
        /// 客户满意度评分（1-5分）
        /// </summary>
        [Range(1, 5, ErrorMessage = "满意度评分必须在1-5分之间")]
        public int? SatisfactionScore { get; set; }

        public Status Urgent { get; set; }

        public List<string> Urls { get; set; }

        public List<WorkOrderHistoryProgress> Progress { get; set; }

    }

    public class GetWorkOrderRapidHistoryDto
    {
        public string OrderNo { get; set; }
        public string PropertiesUUID { get; set; }
        public string FullAddress { get; set; }

        public string Phone { get; set; }

        public WorkOrderRapidStatus Status { get; set; }

        public DateTime CreateTime { get; set; }

        public string Description { get; set; }

        public Status Urgent { get; set; }

        public List<string> Urls { get; set; }

        public List<WorkOrderHistoryProgress> Progress { get; set; }

    }
    public class GetWorkOrderHistoryResponse : GetWorkOrderHistoryDto
    {
        public new bool Urgent { get; set; }
        public new string Status { get; set; }
    }


    public class WorkOrderHistoryProgress
    {
        public string Status { get; set; }
        public string OrderNo { get; set; }
        public string ReasonForChange { get; set; }
        public string ReasonForChangeDescription { get; set; }

        public DateTime UpdateTime { get; set; }

        public bool Urgent { get; set; }
    }
}